package com.googlecode.bindyj.property;

import com.googlecode.bindyj.property.accessor.PropertyAccessor;
import com.googlecode.bindyj.property.listener.PropertyListenerAdapter;
import com.googlecode.bindyj.property.watcher.StaticWatcherProvider;
import com.googlecode.bindyj.property.watcher.Watcher;
import com.googlecode.bindyj.property.watcher.WatcherProvider;

public class AtomicProperty extends AbstractProperty {
  private final PropertyAccessor accessor;
  private final PropertyListenerAdapter listenerAdapter;

  public AtomicProperty(PropertyAccessor accessor,
      PropertyListenerAdapter listenerAdapter) {
    this.accessor = accessor;
    this.listenerAdapter = listenerAdapter;
  }

  public Object get(Object source) {
    return accessor.get(source);
  }

  public void set(Object source, Object value) {
    accessor.set(source, value);
  }

  public WatcherProvider watcherProvider(WatcherProvider childProvider) {
    Watcher watcher = new Watcher(null, accessor, listenerAdapter, childProvider);
    return new StaticWatcherProvider(watcher);
  }

}
